from datetime import datetime

from model import db


def ImgDefault():
    return '/static/img/default.png'

def NowStr():
    return datetime.now().strftime('%Y-%m-%d %H:%M:%S')

class User(db.Model):
    id = db.Column(db.Integer, primary_key=True, autoincrement=True)
    username = db.Column(db.String(300), nullable=False, unique=True)
    password = db.Column(db.String(300), nullable=False)
    time = db.Column(db.String(19), default=NowStr())

    intro = db.Column(db.String(120), default='该用户暂无介绍')
    img_icon = db.Column(db.Text, default=ImgDefault())
    img_background = db.Column(db.Text, default=ImgDefault())
    admin = db.Column(db.Boolean, default=False)
    role = db.Column(db.String(50), default='访客')

    disable_until = db.Column(db.String(19), default=None)


class Blog(db.Model):
    id = db.Column(db.Integer, primary_key=True, autoincrement=True)
    uid = db.Column(db.Integer, nullable=False)
    time = db.Column(db.String(19), default=NowStr())

    sort = db.Column(db.String(50), default='交友')
    title = db.Column(db.String(120), default='该帖子暂无标题')
    content = db.Column(db.Text, default='该帖子暂无内容')

    uid_admin=db.Column(db.Integer, default=0)
    checked = db.Column(db.Boolean, default=False)
    passed = db.Column(db.Boolean, default=False)
    reason = db.Column(db.String(300), default=None)
    time_check = db.Column(db.String(19), default=None)

class Comment(db.Model):
    id = db.Column(db.Integer, primary_key=True, autoincrement=True)
    uid = db.Column(db.Integer, nullable=False)
    pid = db.Column(db.Integer, nullable=False)
    time = db.Column(db.String(19), default=NowStr)
    content = db.Column(db.Text, default='该用户暂无评论')

class Like(db.Model):
    id = db.Column(db.Integer, primary_key=True, autoincrement=True)
    uid = db.Column(db.Integer, nullable=False)
    pid = db.Column(db.Integer, nullable=False)
    time = db.Column(db.String(19), default=NowStr)

class Follow(db.Model):
    id = db.Column(db.Integer, primary_key=True, autoincrement=True)
    uid = db.Column(db.Integer, nullable=False)
    uid1 = db.Column(db.Integer, nullable=False)
    time = db.Column(db.String(19), default=NowStr)

